<template>
  <a-card :bordered="false">
    <!-- 查a询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="showModal1" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('tb_sale_list_goods')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <sale-list-goods-modal ref="modalForm" @ok="modalFormOk"/>

    <div>
      <a-modal
        title="新增"
        :visible="visible1"
        :confirm-loading="confirmLoading1"
        @ok="handleOk"
        @cancel="handleCancel"
        width="1000px"
      >
        <a-table :columns="columns1" :data-source="data">
          <a slot="name" slot-scope="text">{{ text }}</a>
          <span slot="customTitle"><a-icon type="smile-o"/> Name</span>
          <span slot="tags" slot-scope="tags">
      <a-tag
        v-for="tag in tags"
        :key="tag"
        :color="tag === 'loser' ? 'volcano' : tag.length > 5 ? 'geekblue' : 'green'"
      >
        {{ tag.toUpperCase() }}
      </a-tag>
    </span>
          <span slot="action" slot-scope="text, record">
      <a-divider type="vertical"/>
      <a @click="showModal2">添加</a>
    </span>
        </a-table>
      </a-modal>
    </div>
    <!--二级弹窗-->
    <div>
      <a-modal
        title="Title"
        :visible="visible2"
        :confirm-loading="confirmLoading2"
        @ok="handleOk2"
        @cancel="handleCancel2"
      >
        <a-form-model :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-form-model-item label="商品编码">
            <a-input v-model="form.name" disabled="disabled"/>
          </a-form-model-item>
          <a-form-model-item label="商品名称">
            <a-input v-model="form.name" disabled="disabled"/>
          </a-form-model-item>
          <a-form-model-item label="商品型号">
            <a-input v-model="form.name" disabled="disabled"/>
          </a-form-model-item>
          <a-form-model-item label="商品单位">
            <a-input v-model="form.name" disabled="disabled"/>
          </a-form-model-item>
          <a-form-model-item label="销售单价">
            <a-input v-model="form.name" disabled="disabled"/>
          </a-form-model-item>
          <a-form-model-item label="当前库存">
            <a-input v-model="form.name" disabled="disabled"/>
          </a-form-model-item>
          <a-divider />
          <a-form-model-item label="单价">
            <a-input v-model="form.name" />
          </a-form-model-item>
          <a-form-model-item label="数量">
            <a-input v-model="form.name" />
          </a-form-model-item>
        </a-form-model>
      </a-modal>
    </div>
  </a-card>

</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SaleListGoodsModal from './modules/SaleListGoodsModal'
import '@/assets/less/TableExpand.less'

const columns1 = [
  {
    title: '商品编码',
    dataIndex: 'name',
    key: 'name',
    scopedSlots: { customRender: 'name' },
  },
  {
    title: '商品名称',
    dataIndex: 'age',
    key: 'age',
    width: 80,
  },
  {
    title: '商品型号',
    dataIndex: 'address',
    key: 'address 1',
    ellipsis: true,
  },
  {
    title: '单位',
    dataIndex: 'address',
    key: 'address 2',
    ellipsis: true,
  },
  {
    title: '商品单价',
    dataIndex: 'address',
    key: 'address 3',
    ellipsis: true,
  },
  {
    title: '成本均价',
    dataIndex: 'address',
    key: 'address 4',
    ellipsis: true,
  },
  {
    title: '库存数量',
    dataIndex: 'address',
    key: 'address 5',
    ellipsis: true,
  },
  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
  },
]

const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
    tags: ['nice', 'developer'],
  },
]

export default {
  name: 'SaleListGoodsList',
  mixins: [JeecgListMixin],
  components: {
    SaleListGoodsModal
  },
  data() {
    return {
      //表单参数
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      form: {
        name: '',
        region: undefined,
        date1: undefined,
        delivery: false,
        type: [],
        resource: '',
        desc: '',
      },
      //弹窗参数
      visible1: false,
      confirmLoading1: false,
      visible2: false,
      confirmLoading2: false,

      data,
      columns1,
      description: 'tb_sale_list_goods管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '商品编码',
          align: 'center',
          dataIndex: 'goodsCode'
        },
        {
          title: '商品名称',
          align: 'center',
          dataIndex: 'goodsName'
        },
        {
          title: '商品型号',
          align: 'center',
          dataIndex: 'goodsModel'
        },
        {
          title: '销售数量',
          align: 'center',
          dataIndex: 'goodsNum'
        },
        {
          title: '商品单位',
          align: 'center',
          dataIndex: 'goodsUnit'
        },
        {
          title: '商品单价',
          align: 'center',
          dataIndex: 'price'
        },
        {
          title: '总金额',
          align: 'center',
          dataIndex: 'total'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        }
      ],
      url: {
        list: '/sale/saleListGoods/list',
        delete: '/sale/saleListGoods/delete',
        deleteBatch: '/sale/saleListGoods/deleteBatch',
        exportXlsUrl: '/sale/saleListGoods/exportXls',
        importExcelUrl: 'sale/saleListGoods/importExcel',

      },
      dictOptions: {},
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    //我的
    showModal1() {
      this.visible1 = true
    },
    handleOk(e) {
      this.ModalText = 'The modal will be closed after two seconds'
      this.confirmLoading = true
      setTimeout(() => {
        this.visible1 = false
        this.confirmLoading = false
      }, 2000)
    },
    handleCancel(e) {
      console.log('Clicked cancel button')
      this.visible1 = false
    },

    showModal2() {
      this.visible2 = true;
    },
    handleOk2(e) {
      this.ModalText = 'The modal will be closed after two seconds';
      this.confirmLoading = true;
      setTimeout(() => {
        this.visible2 = false;
        this.confirmLoading = false;
      }, 2000);
    },
    handleCancel2(e) {
      console.log('Clicked cancel button');
      this.visible2 = false;
    },

    //表单提交
    onSubmit() {
      console.log('submit!', this.form);
    },

    initDictConfig() {
    },

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>